package ysu.sxm.ptjc.Controller;

import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import ysu.sxm.ptjc.Domin.DefectReq;
import ysu.sxm.ptjc.Domin.DefectTopCondition;
import ysu.sxm.ptjc.Service.DefectStatisticsService;

import javax.xml.crypto.Data;
import java.util.Date;

@RestController
@RequestMapping("/defect")
public class DefectServlet {
    @Autowired
    DefectStatisticsService defectStatisticsService;
    @PostMapping(path = "")
    public String defect(@RequestBody DefectReq defectReq){
        System.out.println(defectReq.toString());
        String res=JSON.toJSONString(defectStatisticsService.defect(defectReq));
        System.out.println(res);
        return res;
    }
    @PostMapping(path = "/top")
    public String defTop(@RequestBody DefectTopCondition topCondition){
        if (topCondition.getValue()==null){
            topCondition.setValue(10);
        }
        if (topCondition.getMonth()==null){
            Date d=new Date();
            topCondition.setMonth(d.getMonth()+1);
        }
        return defectStatisticsService.defTop(topCondition);
    }
}
